﻿// <copyright file="Window1.xaml.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-02-18</date>
// <summary>OpenWPFChart library. ChartScaleControl Test project main window.</summary>
// <revision>$Id$</revision>

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using OpenWPFChart.Parts;

namespace ChartScaleControlTest
{
	/// <summary>
	/// ChartScaleControl test project main window.
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		public Window1()
		{
			InitializeComponent();
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			setLinearScale();
		}

		void setMenuCheckMark(MenuItem checkedItem)
		{
			foreach (MenuItem item in mnuScales.Items)
			{
				if (item == checkedItem)
					item.IsChecked = true;
				else
					item.IsChecked = false;
			}
		}

		void setLinearScale()
		{
			ChartScale scale = new ChartLinearScale()
			{
				Start = 0,
				Stop = 100,
				Scale = 1,
				TickStep = 1
			};
			chartScaleCtrl.ChartScale = scale;
			setMenuCheckMark(mnuLinearScale);
		}

		void setLogScale()
		{
			ChartScale scale = new ChartLogarithmicScale()
			{
				Start = 1,
				Stop = 100,
				Scale = 1
			};
			chartScaleCtrl.ChartScale = scale;
			setMenuCheckMark(mnuLogScale);
		}

		void setDateTimeScale()
		{
			ChartScale scale = new ChartDateTimeScale()
			{
				Start = new DateTime(2008, 1, 1),
				Stop = new DateTime(2009, 12, 1),
				TickUnits = DateTimeTickUnits.Months,
			};
			chartScaleCtrl.ChartScale = scale;
			setMenuCheckMark(mnuDateTimeScale);
		}

		void setSeriesScale()
		{
			List<string> series = new List<string>()
			{
			    "first",
			    "second",
			    "third",
			    "fourth",
			    "fifth",
			    "sixth",
			    "seventh",
			    "eighth",
			    "ninth",
			    "tenth",
			};
			ChartSeriesScale scale = new ChartSeriesScale()
			{
				Series = series,
				Start = series[0],
				Stop = series[series.Count - 1]
			};
			chartScaleCtrl.ChartScale = scale;
			setMenuCheckMark(mnuSeriesScale);
		}

		private void mnuScales_Click(object sender, RoutedEventArgs e)
		{
			MenuItem item = sender as MenuItem;
			if (item == null)
				return;
			switch (item.Name)
			{
				case "mnuLinearScale":
					setLinearScale();
					break;
				case "mnuLogScale":
					setLogScale();
					break;
				case "mnuDateTimeScale":
					setDateTimeScale();
					break;
				case "mnuSeriesScale":
					setSeriesScale();
					break;
			}
		}
	}
}
